import {EggAppConfig, EggAppInfo, PowerPartial} from 'egg';

export default (appInfo: EggAppInfo) => {
    const config = {} as PowerPartial<EggAppConfig>;

    // override config from framework / plugin
    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_zjsj_lize';

    // add your egg config in here
    config.middleware = [];

    // add your special config in here
    const bizConfig = {
        sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
    };

    let mongoose: any = {
        client: {
            url: 'mongodb://127.0.0.1/eggadmin',
            options: {
                server: {
                    poolSize: 40,
                }
            },
        },
    };
    config.mongoose = mongoose

    config.cluster = {
        listen: {
            port: 8081
        }
    };
    config.view = {
        defaultViewEngine: 'nunjucks',
        defaultExtension: '.nj',
        mapping: {
            '.nj': 'nunjucks',
        },
    }
    config.security = {
        csrf: {
            enable: false
        },
        domainWhiteList: ['*']
    };
    config.cors = {
        origin: '*',
        allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
    };
    // add your user config here
    const userConfig = {
        // myAppName: 'egg',
    };
    // the return config will combines to EggAppConfig
    return {
        ...config as {},
        ...bizConfig,
        ...userConfig
    };
};
